package com.ajnp.springcloud.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class GatewayConfig {
    //https://news.qq.com/

    @Bean
    public RouteLocator setrouteLocator(RouteLocatorBuilder routeLocatorBuilder) {
        //创建 RouteLocatorBuilder 工厂 创建 RouteLocator对象
        RouteLocatorBuilder.Builder routes = routeLocatorBuilder.routes();
        //设置网关的遮掩  当请求的路径为 http://localhost:9527/txxw 实则会将请求转发到 https://news.qq.com/ 路径
        routes.route("path_route_ajnp", r -> r.path("/txxw")
                .uri("http://news.baidu.com/guonei")).build();
        return routes.build();
    }


}
